<template>
	<view>
		<view class="cu-form-group" v-for="(item,index) in settingList" :key="index">
			<view class="cu-form-box" @tap="showModal(index)">
				<view class="title">{{item.Default_Name}}</view>
				<view class="title1 ">{{item.Default_Value}}</view>
			</view>
			<view class="" v-if="item.Default_Value.length>0" @tap="clearInput(index)">
				<text class="cuIcon-close"></text>
			</view>
		</view>
		<view class="cu-modal" :class="modal?'show':'hide'" @tap="hideModal">
			<view class="cu-dialog" @tap.stop="">
				<view class="cu-bar bg-white justify-end">
					<view class="content">供应商选择</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-blue"></text>
					</view>
				</view>
				<view class="padding-xl bg-white">
					<view class="searchStore">
						<input placeholder="请输入名称" v-model="SearchCName" />
						<button @tap="searchStore(0)">搜索</button>
					</view>
					<view class="StoreListWrap">
						<view v-for="(item,index) in GYSList" :key="index" @tap="gysChange(index)">{{item.ClientName}}</view>
					</view>
				</view>
			</view>
		</view>
		<!--客户model-->
		<view class="cu-modal" :class="CustomerModal?'show':'hide'" @tap="hideModal1">
			<view class="cu-dialog" @tap.stop="">
				<view class="cu-bar bg-white justify-end">
					<view class="content">客户选择</view>
					<view class="action" @tap="hideModal1">
						<text class="cuIcon-close text-blue"></text>
					</view>
				</view>
				<view class="padding-xl bg-white">
					<view class="searchStore">
						<input placeholder="请输入名称" v-model="SearchCName" />
						<button @tap="searchStore(1)">搜索</button>
					</view>
					<view class="StoreListWrap">
						<view v-for="(item,index) in KHList" :key="index" @tap="CustomerChange(index)">{{item.ClientName}}</view>
					</view>
				</view>
			</view>
		</view>
		<!--业务员model-->
		<view class="cu-modal" :class="YWYModal?'show':'hide'" @tap="hideModal2">
			<view class="cu-dialog" @tap.stop="">
				<view class="cu-bar bg-white justify-end">
					<view class="content">业务员选择</view>
					<view class="action" @tap="hideModal2">
						<text class="cuIcon-close text-blue"></text>
					</view>
				</view>
				<!-- <radio-group class="block" @change="EChange">
					<view class="cu-list menu text-left">
						<view class="cu-item" v-for="(item,index) in EmpList" :key="index">
							<label class="flex justify-between align-center flex-sub">
								<view class="title1">{{item.OperatorName}}</view>
								<radio class="round" :class="radio=='radio'?'checked':''" :checked="radio=='radio'?true:false" :value="item.OperatorName"></radio>
							</label>
						</view>
					</view>
				</radio-group> -->
				<view class="padding-xl bg-white">
					<view class="StoreListWrap">
						<view v-for="(item,index) in EmpList" :key="index" @tap="EChange(index)">{{item.OperatorName}}</view>
					</view>
				</view>
			</view>
		</view>
		<!--仓库model-->
		<view class="cu-modal" :class="StockModal?'show':'hide'" @tap="hideModal3">
			<view class="cu-dialog" @tap.stop="">
				<view class="cu-bar bg-white justify-end">
					<view class="content">仓库选择</view>
					<view class="action" @tap="hideModal3">
						<text class="cuIcon-close text-blue"></text>
					</view>
				</view>
				<!-- <radio-group class="block" @change="StockChange">
					<view class="cu-list menu text-left">
						<view class="cu-item" v-for="(item,index) in storeList" :key="index">
							<label class="flex justify-between align-center flex-sub">
								<view class="title1">{{item.StoreName}}</view>
								<radio class="round" :class="radio=='radio'?'checked':''" :checked="radio=='radio'?true:false" :value="item.StoreName"></radio>
							</label>
						</view>
					</view>
				</radio-group> -->
				<view class="padding-xl bg-white">
					<view class="StoreListWrap">
						<view v-for="(item,index) in storeList" :key="index" @tap="StockChange(index)">{{item.StoreName}}</view>
					</view>
				</view>
			</view>
		</view>
		<!--光标跳转model-->
		<view class="cu-modal" :class="RadioModal?'show':'hide'" @tap="hideModal4">
			<view class="cu-dialog" @tap.stop="">
				<view class="cu-bar bg-white justify-end">
					<view class="content">光标跳转</view>
					<view class="action" @tap="hideModal4">
						<text class="cuIcon-close text-blue"></text>
					</view>
				</view>
				<view class="padding-xl bg-white">
					<view class="StoreListWrap">
						<view v-for="(item,index) in gbtzList" :key="index" @tap="RadioChange(index)">{{item.name}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import * as Api from '@/syApis/syBb/apis.js';
	import * as Api1 from '@/syApis/sySet/sySet.js';
	import * as Api2 from '@/syApis/syAddOrder/syaddApis.js'

	export default {
		data() {
			return {
				gbtzList: [{
						name: "单价"
					},
					{
						name: "数量"
					}
				],
				settingList: [{
					Default_ID:"",
					Default_Name:"供应商",
					Default_Value:""
				},{
					Default_ID:"",
					Default_Name:"客户",
					Default_Value:""
				},{
					Default_ID:"",
					Default_Name:"业务员",
					Default_Value:""
				},{
					Default_ID:"",
					Default_Name:"仓库",
					Default_Value:""
				},{
					Default_ID:"",
					Default_Name:"光标跳转",
					Default_Value:""
				}],
				// modalName: null,
				modal: false,
				CustomerModal: false,
				StockModal: false,
				YWYModal: false,
				ClientNameList: [],
				EmpList: [],
				List: [],
				storeList: [],
				GYSList: [],
				List1: [],
				KHList: [],
				List2: [],
				radio: '',
				RadioModal: false,
				SearchCName: ''
			}
		},
		created() {
			let date = new Date();
			this.GetStoreMessage();
			this.GetOperatorMessage();
			this.GetClientMessage();
			this.getDefaultSettingInfo();
			this.GetClient1Message();
		},
		methods: {
			//获取默认设置信息
			getDefaultSettingInfo() {
				let data = {};
				var that = this;
				Api1.Get_Set_Default(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "No connection could be made because the target machine actively refused it") {

						} else if (res.data.ErrorMsg != "") {

						} else {
							// //console.tablele(res.data.ResultMsg);
							//赋值数组
							if(res.data.ResultMsg.length!=0){
								that.settingList = res.data.ResultMsg;
							}
							

						}
					} else {

					}
				})
			},
			//获取供应商信息
			GetClientMessage(Filter='') {
				let data = {
					Filter: "IsClient<>1" + Filter
				};
				var _this = this;
				Api.GetClientMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {

						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							_this.List1 = [];
							_this.SearchCName ="";
							_this.GYSList = res.data.ResultMsg;
							for (let item in res.data.ResultMsg) {
								// //console.tablele(res.data.ResultMsg)
								_this.List1.push(res.data.ResultMsg[item].ClientName);
							}
						}
					} else {
						Api.ShowTip("服务器开小差了");
					}
				})
			},
			//获取客户
			GetClient1Message(Filter='') {
				let data = {
					Filter: "IsClient<>0" + Filter
				};
				var _this = this;
				Api.GetClientMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {
			
						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							_this.List2 = [];
							_this.SearchCName ="";
							_this.KHList = res.data.ResultMsg;
							for (let item in res.data.ResultMsg) {
								// //console.tablele(res.data.ResultMsg)
								_this.List1.push(res.data.ResultMsg[item].ClientName);
							}
						}
					} else {
						Api.ShowTip("服务器开小差了");
					}
				})
			},
			//获取员工档案
			GetOperatorMessage() {
				let data = {};
				var _this = this;
				Api.GetOperatorMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {

						} else if (res.data.ErrorMsg != "") {
							Api.showTip(res.data.ErrorMsg);
						} else {
							_this.ClientNameList = [];
							_this.EmpList = res.data.ResultMsg;
							for (let item in res.data.ResultMsg) {
								// //console.tablele(res.data.ResultMsg)
								_this.ClientNameList.push(res.data.ResultMsg[item].OperatorName);
							}
						}
					} else {
						Api.ShowTip("服务器开小差了");
					}
				})
			},
			//获取仓库档案
			GetStoreMessage() {
				let data = {};
				var _this = this;
				Api2.GetStoreMessage(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == '获取登录信息失败') {

						} else if (res.data.ErrorMsg != "") {
							Api2.showTip(res.data.ErrorMsg);
						} else {
							_this.List = [];
							_this.storeList = res.data.ResultMsg;
							for (let item in res.data.ResultMsg) {
								// //console.tablele(res.data.ResultMsg)
								_this.List.push(res.data.ResultMsg[item].StoreName);
							}
						}
					} else {
						Api2.ShowTip("服务器开小差了");
					}
				})
			},
			gysChange(e) {
				console.log(e)
				this.modal = false;
				this.settingList[0].Default_Value = this.GYSList[e].ClientName;;
				this.settingList[0].Default_ID = this.GYSList[e].ClientID;;
			},
			CustomerChange(e) {
				console.log(e)
				this.CustomerModal = null;
				// this.settingList[1].Default_Value = e.detail.value;
				this.settingList[1].Default_Value = this.KHList[e].ClientName;
				this.settingList[1].Default_ID = this.KHList[e].ClientID;
			},
			EChange(e) {
				console.log(e)
				this.YWYModal = null;
				this.settingList[2].Default_Value = this.EmpList[e].OperatorName;
				this.settingList[2].Default_ID = this.EmpList[e].OperatorID;
			},
			StockChange(e) {
				console.log(e)
				this.StockModal = null;
				this.settingList[3].Default_Value = this.storeList[e].StoreName;
				this.settingList[3].Default_ID = this.storeList[e].StoreID;
			},
			RadioChange(e) {
				this.RadioModal = null;
				this.settingList[4].Default_Value = this.gbtzList[e].name;
			},
			//清除默认设置内容
			clearInput(selectIndex) {
				this.settingList[selectIndex].Default_Value = "";
				this.settingList[selectIndex].Default_ID = "";
			},
			hideModal(selectIndex) {
				this.modal = false;
			},
			hideModal1(selectIndex) {
				this.CustomerModal = false;
			},
			hideModal2(selectIndex) {
				this.YWYModal = false;
			},
			hideModal3(selectIndex) {
				this.StockModal = false;
			},
			hideModal4(selectIndex) {
				this.RadioModal = false;
			},
			showModal(e) {
				console.log(e)
				if (e == 0) {
					this.modal = true
					for (let item in this.GYSList) {
						if (item == e.index) {
							this.ClientName = this.GYSList[item].ClientID;
						}
					}
				} else if (e == 1) {
					this.CustomerModal = true
					for (let item in this.KHList) {
						if (item == e.index) {
							this.ClientName = this.KHList[item].ClientID;
						}
					}
				} else if (e == 2) {
					this.YWYModal = true
					for (let item in this.EmpList) {
						if (item == e.index) {
							this.EName = this.EmpList[item].OperatorID;
						}
					}
				} else if (e == 3) {
					this.StockModal = true
					// console.log(selectindex)
					for (let item in this.storeList) {
						if (item == e.index) {
							this.SName = this.storeList[item].StoreID;
						}
					}
				} else if (e == 4) {
					// console.log(selectindex)
					this.RadioModal = true
				}
			},
			// #ifndef MP			
			onNavigationBarButtonTap(e) {
				const index = e.index;
				// console.log(index)				
				if (index === 0) {
					console.log(index)
					var _this = this;
					var Save_D_Data_Json = [];
					// this.settingList.forEach((item, index) => {}
					this.settingList.forEach((item, index) => {
						let itemData = {
							Default_Name: item.Default_Name,
							Default_ID: item.Default_ID,
							Default_Value: item.Default_Value
						};
						Save_D_Data_Json.push(itemData);
					});
					// Save_D_Data_Json: JSON.stringify(Save_D_Data_Json),
					let data = {
						Save_D_Data_Json: JSON.stringify(Save_D_Data_Json),
					};
					Api1.Save_Set_Default(data, function(res) {
						if (res.state) {
							if (res.data.ErrorMsg == "获取登录信息失败") {
								Api1.showTip("登录超时");
							} else if (res.data.ErrorMsg != "") {
								Api1.showTip(res.data.ErrorMsg);
							} else {
								// _this.settingList = [];
								//console.tablele(_this.settingList)
								Api1.showTip("提交成功");
								// return;
							}
						} else {

						}
					});
				}
				// this.DrawerModalL = e.currentTarget.dataset.target
			},


			// #endif
			//搜索
			searchStore(index) {
				if(index==0){
					if (this.SearchCName != '') {
						let Filter = "and ClientName like '%" + this.SearchCName + "%'";
						this.GetClientMessage(Filter);
					} else {
						this.GetClientMessage();
					}
				}else if(index==1){
					if (this.SearchCName != '') {
						let Filter = "and ClientName like '%" + this.SearchCName + "%'";
						this.GetClient1Message(Filter);
					} else {
						this.GetClient1Message();
					}
				}
				
			},
			
		},
		
	}
</script>


<style lang="scss" scoped>
	pages {
		background: #FFFFFF;
	}

	.cu-form-box {
		display: flex;
		align-items: center;
		width: 100%;
	}

	.title {
		min-width: 160rpx;
		text-align: right;
	}

	.title1 {
		padding-right: 14px;
		font-size: 14px;
		position: relative;
		height: 28px;
		line-height: 28px;
	}

	.padding-xl .searchStore {
		display: flex;
		width: 100%;
		margin: auto;
		height: 45px;
		padding-top: 5px;
		font-size: 14px;
	}

	.padding-xl .searchStore input {
		flex: 1;
		height: 35px;
		border: 1px solid #CCC;
		border-top-left-radius: 5px;
		border-bottom-left-radius: 5px;
		padding-left: 10px;
	}

	.padding-xl {
		padding: 10px;

	}

	.padding-xl .searchStore button {
		font-size: 14px;
		color: #FFF;
		padding-left: 8px;
		padding-right: 8px;
		height: 35px;
		line-height: 35px;
		border-radius: 0px;
		border-top-right-radius: 5px;
		border-bottom-right-radius: 5px;
		text-align: center;
		background: rgba(124, 170, 216, 1);
	}

	.padding-xl .StoreListWrap {
		height: 250px;
		overflow: auto;
	}

	.padding-xl .StoreListWrap view {
		height: 40px;
		line-height: 40px;
		text-align: left;
		border-bottom: 1px solid #CCC;
		padding-left: 8px;
		font-size: 15px;
	}

	.cu-form-group {
		padding: 1px 10px !important;
		height: 40px;
		line-height: 40px;
		min-height: 40px;
	}
</style>
